$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加需求报名', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [ {
                title: '需求标题',
                unresize: true,
                align: 'center',
                width:'20%',
                templet:function(d){
                 return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;padding:0 10px" lay-event="title" >'+d.title+'</div>';
                }
            },{
                title: '申请人编号',
                unresize: true,
                align: 'center',
                templet:function(d){
                 return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC" lay-event="user" >'+parseInt(d.apply_user + 10000)+'</div>';
                },
                width:'10%'
            }, {
                field: 'price',
                title: '收益金额',
                unresize: true,
                align: 'center',
                width:'10%'
            }, {
                field: 'order_no',
                title: '订单编号',
                unresize: true,
                align: 'center',
                width:'20%'
            },  {
                title: '支付方式',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.pay_type){
                        case 0: return '余额';break;
                        case 1: return '微信';break;
                        case 2: return '支付宝';break;
                    }
                },
                width:'10%'
            }, {
                field: 'pay_time',
                title: '支付时间',
                unresize: true,
                align: 'center',
                width:'15%'
            }, {
                field: 'apply_time',
                title: '申请时间',
                unresize: true,
                align: 'center',
                width:'15%'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑需求报名', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该需求报名吗?', 'bz_need_apply', obj.data.id);
        }else if (obj.event === 'user') {
            layer_iframe('会员信息', '/before/user/index?id=' + obj.data.apply_user);

        }else if (obj.event === 'title') {
            layer_iframe('需求详情', '/before/need/index?id=' + obj.data.foreign_key);

        }
    });
});
